package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 别名
 */
public class JDBCDemo6 {
    public static void main(String[] args) {
        /**
         * 查看1年级1班一共多少人
         */
        try (
                Connection connection = DBUtil.getConnection();
                ){
           Statement statement = connection.createStatement();
           String sql= "SELECT COUNT(*) count "+
                   "FROM class C "+
                   "JOIN student s ON c.id=s.class_id "+
                   "WHERE c.name='1年级1班' ";
           ResultSet rs=statement.executeQuery(sql);
           while(rs.next()){
               int count=rs.getInt("count");
               System.out.println("人数：" + count);
           }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
